<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        #context1 {
            width: 400px;
            height: 400px;
            background-color: pink;
        }

        #context2 {
            width: 400px;
            height: 400px;
            background-color: pink;
        }

        #colorbox1 {
            width: 300px;
            height: 300px;
            background-color: aqua;
        }

        #colorbox1 div {
            width: 200px;
            height: 200px;
            background-color: yellow;
        }

        button {
            width: 100px;
            height: 50px;
        }
    </style>
</head>

<body>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>
    <div id="box">
        <button @click="t1()">tag1</button>
        <button @click="t2()">tag2</button>
        <div id="context1" v-if="num==1">
            <a href="https://cn.bing.com/" v-on:click.prevent="fun()">百度（阻止默认事件，点击不跳转）</a>
        </div>
        <div id="context2" v-if="num==2">
            <div @click="d1()" id="colorbox1">
                大盒子点击变蓝
                <div @click.stop="d2()" id="colorbox2">
                    小盒子点击变红(阻止事件冒泡，点击大盒子不变色)
                </div>
            </div>
        </div>
    </div>
    <script>
        new Vue({
            el: "#box",
            data: {
                num: 1
            },
            methods: {
                t1() {
                    return this.num = 1
                },
                t2() {
                    return this.num = 2
                },
                d1() {
                    var colorbox1 = document.getElementById("colorbox1")
                    colorbox1.style.backgroundColor = "blue"
                },
                d2() {
                    var colorbox2 = document.getElementById("colorbox2")
                    colorbox2.style.backgroundColor = "red"
                },
                fun() {
                }
            }
        })
    </script>
</body>

</html>